package com.one.service.impl;

import com.one.dto.AdminLoginDTO;
import com.one.entity.Admin;
import com.one.exception.BaseException;
import com.one.mapper.AdminMapper;
import com.one.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;


    /**
     * 管理员登录
     * @param adminLoginDTO 登录信息
     * @return 管理员信息
     */
    public Admin login(AdminLoginDTO adminLoginDTO) {
        Admin admin = adminMapper.getByAdminCode(adminLoginDTO.getAdminCode());
        if (admin == null ) {
            log.error("管理员登录失败，管理员编码 {} 不存在", adminLoginDTO.getAdminCode());
            return null;
        }
        if(!admin.getPassword().equals(adminLoginDTO.getPassword())){
            log.error("管理员登录失败，密码错误，adminCode: {}", adminLoginDTO.getAdminCode());
            return null;
        }
        return admin;
    }

}
